package mysql

import (
	"gorm.io/gorm"
	"user-login-reg/regrpc/regrpc"
)

type Goods struct {
	gorm.Model
	GoodsName  string  `gorm:"varchar(50);not null;commit:'商品名称'"`
	GoodsPrice float32 `gorm:"decimal(10,2);not null;commit:'商品价格'"`
	GoodsNum   int     `gorm:"int;not null;commit:'商品数量'"`
	UserId     int     `gorm:"int;not null;commit:'用户编号'"`
}

func (g *Goods) GoodsAdd(db *gorm.DB) error {
	return db.Create(g).Error
}

func (g *Goods) FindGoods(db *gorm.DB, id int64) ([]*regrpc.GoodsList, error) {
	var list []*regrpc.GoodsList
	err = db.Where("id=?", id).Model(g).Find(list).Error
	return list, err
}
